package com.itbaima.csmall.cart.webapi.mapper;

import com.itbaima.csmall.commons.pojo.cart.entity.Cart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

/**
 * <p>购物车商品的数据访问层</p>
 *
 * @author Chen
 * @since 2023/2/20 10:25:25
 */
@Repository
public interface CartMapper {

    /**
     * 添加购物车
     *
     * @param cart 购物车
     */
    @Insert("INSERT INTO cart_tbl(commodity_code, user_id, price, count) VALUES (#{commodityCode},#{userId},#{price},#{count})")
    void insertCart(Cart cart);

    /**
     * 根据用户ID和商品编码删除购物车
     *
     * @param userId        用户ID
     * @param commodityCode 商品编码
     */
    @Delete("DELETE FROM cart_tbl WHERE user_id = #{userId} AND commodity_code = #{commodityCode}")
    void deleteCartByUserIdAndCommodityCode(@Param("userId") String userId, @Param("commodityCode") String commodityCode);

}
